package com.sub.service.impl;

import com.sub.mapper.SpFirstMenuMapper;
import com.sub.model.SpFirstMenu;
import com.sub.service.FirstMenuService;
import com.sub.utils.PageList;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FirstMenuServiceImpl implements FirstMenuService{

	@Autowired
	private SpFirstMenuMapper spFirstMenuMapper;

	@Autowired
	private Sid sid;

	@Override
	public List<SpFirstMenu> queryFirstMenuList(SpFirstMenu spFirstMenu) {
		return spFirstMenuMapper.select(spFirstMenu);
	}

	@Override
	public PageList queryFirstMenuByPageAndName(PageList pageList,int page, String name) {
		int size = pageList.getSize();
        pageList.setTotal(spFirstMenuMapper.selectCountS(name));
        pageList.setList(spFirstMenuMapper.getFirstMenuForPage(name,(page-1)*size,size));
		return pageList;
	}

	@Override
	public int saveFirst(SpFirstMenu firstMenu) {
		firstMenu.setSpFirstMenuId(sid.nextShort());
		return spFirstMenuMapper.insert(firstMenu);
	}

	@Override
	public int editFirst(SpFirstMenu firstMenu) {
		return spFirstMenuMapper.updateByPrimaryKeySelective(firstMenu);
	}

	@Override
	public int removeFirstById(String firstMenuId) {
		return spFirstMenuMapper.deleteByPrimaryKey(firstMenuId);
	}

	@Override
	public int batchRemoveFirstByIdS(String[] ids) {
		return spFirstMenuMapper.batchRemoveFirstByIdS(ids);
	}
}
